package com.peycard.common;

import java.io.Serializable;

public class Tag implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7165900921672287697L;
	/**
	 * Nombre del tag
	 */
	private String tagName;
	/**
	 * Longitud en hexadecimal
	 */
	private String lengthHex;	
	/**
	 * Longitud en decimal
	 */
	private int lengthDecimal;
	/**
	 * Valor del Tag
	 */
	private String value;
	/**
	 * @return el tagName
	 */
	public String getTagName() {
		return tagName;
	}
	/**
	 * @param tagName el tagName a establecer
	 */
	public void setTagName(String tagName) {
		this.tagName = tagName;
	}
	/**
	 * @return el lengthHex
	 */
	public String getLengthHex() {
		return lengthHex;
	}
	/**
	 * @param lengthHex el lengthHex a establecer. Una vez establecido este valor, el decimal se calcula solo y se settea en automatico
	 */
	public void setLengthHex(String lengthHex) {
		int decimal = Integer.parseInt(lengthHex, 16);
		setLengthDecimal(decimal * 2);
		this.lengthHex = lengthHex;
	}
	/**
	 * @return el lengthDecimal
	 */
	public int getLengthDecimal() {
		return lengthDecimal;
	}
	/**
	 * @param lengthDecimal el lengthDecimal a establecer
	 */
	public void setLengthDecimal(int lengthDecimal) {
		this.lengthDecimal = lengthDecimal;
	}
	/**
	 * @return el value
	 */
	public String getValue() {
		return value;
	}
	/**
	 * @param value el value a establecer
	 */
	public void setValue(String value) {
		this.value = value;
	}
	/* (sin Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((tagName == null) ? 0 : tagName.hashCode());
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}
	/* (sin Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Tag other = (Tag) obj;
		if (tagName == null) {
			if (other.tagName != null)
				return false;
		} else if (!tagName.equals(other.tagName))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}
	/* (sin Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Tag [tagName=" + tagName + ", lengthHex=" + lengthHex
				+ ", lengthDecimal=" + lengthDecimal + ", value=" + value + "]";
	}
	
}
